$(function () {
    initMenu();

    $("#min_title_list li").contextMenu('Hui-admin-menu', {
        bindings: {
            'closeThis': function (t) {
                if (t.find("i")) {
                    t.find("i").trigger("click");
                }
            },
            'closeAll': function (t) {
                alert('Trigger was ' + t.id + '\nAction was Email');
            },
        }
    });
});

function initMenu() {
    $.ajax({
        url: "/Olala/server/menu",
        dataType: "json",
        type: "post",
        async: false,
        success: function (result) {
            if (result.code === 20) {
                var menus = result.data;
                var menusStr = "<div class='menu_dropdown bk_2'>";
                for (var i = 0; i < menus.length; i++) {
                    var icons = menus[i].icon.split(",");
                    if (icons == null || icons.length < 0) {
                        icons = ["", ""];
                    }
                    menusStr += "<dl id='" + icons[0] + "'>" +
                        "            <dt><i class='Hui-iconfont'>" + icons[1] + "</i>" + menus[i].menuName + "<i class='Hui-iconfont menu_dropdown-arrow'>&#xe6d5;</i></dt>" +
                        "            <dd>" +
                        "                <ul>";
                    for (var j = 0; j < menus[i].son.length; j++) {
                        menusStr += "<li><a data-href='" + menus[i].son[j].url + "' data-title='" + menus[i].son[j].menuName + "' href='javascript:void(0)'>" + menus[i].son[j].menuName + "</a></li>"
                    }
                    menusStr += " </ul>" +
                        "            </dd>" +
                        "        </dl>";
                }
                menusStr += "</div>";
                $("#menu").append(menusStr);
            }
        }
    });
}

/*个人信息*/
function myselfinfo() {
    layer.open({
        type: 1,
        area: ['300px', '200px'],
        fix: false, //不固定
        maxmin: true,
        shade: 0.4,
        title: '查看信息',
        content: '<div>管理员信息</div>'
    });
}

/*资讯-添加*/
function article_add(title, url) {
    var index = layer.open({
        type: 2,
        title: title,
        content: url
    });
    layer.full(index);
}

/*图片-添加*/
function picture_add(title, url) {
    var index = layer.open({
        type: 2,
        title: title,
        content: url
    });
    layer.full(index);
}

/*产品-添加*/
function product_add(title, url) {
    var index = layer.open({
        type: 2,
        title: title,
        content: url
    });
    layer.full(index);
}

/*用户-添加*/
function member_add(title, url, w, h) {
    layer_show(title, url, w, h);
}